package org.lease.web.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.lease.common.result.Result;
import org.lease.model.dto.RoomItemDTO;
import org.lease.model.query.RoomPageQuery;
import org.lease.model.vo.RoomDetailVo;
import org.lease.service.RoomInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "房间信息")
@RestController
@RequestMapping("/app/room")
public class RoomController {
    @Autowired
    private RoomInfoService roomInfoService;

    @Operation(summary = "分页条件查询房间列表")
    @GetMapping("/pageItem")
    public Result<IPage<RoomItemDTO>> pageQuery(RoomPageQuery query) {
        IPage<RoomItemDTO> page = new Page<>(query.getCurrent(), query.getSize());
        IPage<RoomItemDTO> result = roomInfoService.pageQueryAppRoomItem(page, query);
        return Result.success(result);
    }

    @Operation(summary = "根据 ID 查询房间详细信息")
    @GetMapping("/getDetailById")
    public Result<RoomDetailVo> getDetailById(Long id) {
        RoomDetailVo vo = roomInfoService.getAppRoomDetailById(id);
        return Result.success(vo);
    }

    @Operation(summary = "根据公寓id分页查询房间列表")
    @GetMapping("/pageItemByApartmentId")
    public Result<IPage<RoomItemDTO>> pageItemByApartmentId(@RequestParam long current, @RequestParam long size, @RequestParam Long id) {
        IPage<RoomItemDTO> page = new Page<>(current, size);
        RoomPageQuery query = new RoomPageQuery();
        query.setApartmentId(id);
        IPage<RoomItemDTO> result = roomInfoService.pageQueryAppRoomItem(page, query);
        return Result.success(result);
    }
}
